package com.graduate.daydayup.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @Author: 张
 * @Email: 1271396448@qq.com
 * @Date: 2019/5/17 1:12 PM
 *
 * 时间日期工具类
 */
public class DateFormatUtil {

    /**
     * 获取当前日期
     * @return
     */
    public static final String getCurrentDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        return sdf.format(new Date());
    }

    /**
     * 获取当前日期
     * @return
     */
    public static final String getCurrentTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH-mm-ss");
        return sdf.format(new Date());
    }

    /**
     * 获取当前年月
     */
    public static final String getDateYearMonth(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return sdf.format(new Date());
    }

    /**
     * 获取当前月日
     */
    public static final String getDateMonthDay(){
        SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
        return sdf.format(new Date());
    }



    /**
     * Date转年月日格式
     * @param date
     * @return 2018-01-01
     */
    public static String dateToYearMonthDay(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return format.format(date);
    }

    /**
     * 时间戳转日期
     * @return 2018-01-01
     */
    public static String timestampToDate(long timeStamp) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        @SuppressWarnings("unused")
        long lcc = Long.valueOf(timeStamp);
        String times = sdr.format(new Date(timeStamp));
        return times;
    }


    /**
     * 时间戳转 年月日时分
     * @return 2018-01-01 01:01
     */
    public static String timestampToDateHourMinutes(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        String times = sdf.format(new Date(time));
        return times;
    }

    /**
     * 时间戳转 年月日时分秒
     * @return 2018-01-01 01:01:01
     */
    public static String timestampToDateHourMinutesSecond(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        String times = sdf.format(new Date(time));
        return times;
    }

    public static String timestampToHourMinutes(long time){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        String times = sdf.format(new Date(time));
        return times;
    }

    /**
     * 时间戳转 月日时分
     * @return 01-01 01:01
     */
    public static String timestampToMonthDayHourMinutes(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        String times = sdf.format(new Date(time));
        return times;
    }

    /**
     * 时间戳转 月日时分秒
     * @return 01-01 01:01:01
     */
    public static String timestampToMonthDayHourMinutesSeconds(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        String times = sdf.format(new Date(time));
        return times;
    }

    /**
     * date格式转日期时分秒
     * @return 2018-01-01 01:01:01
     */
    public static String dateToDateHourMinutesSecond(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return sdf.format(date);
    }

}
